package cn.tedu.property_management_system.controller;

import cn.tedu.property_management_system.entity.VO.AdministratorVO;
import cn.tedu.property_management_system.entity.dto.AdministratorDTO;
import cn.tedu.property_management_system.entity.dto.AdministratorDTV;
import cn.tedu.property_management_system.service.AdministratorService;
import cn.tedu.property_management_system.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/administrator")
public class AdministratorController {

    @Autowired
    private AdministratorService administratorService;

    @PostMapping("/add")
    public JsonResult<Void> add(@RequestBody AdministratorDTO administratorDTO) {
        administratorService.add(administratorDTO);
        return JsonResult.OK();
    }

    @GetMapping("/select")
    public JsonResult<List<AdministratorVO>> select() {
        List<AdministratorVO> list = administratorService.getAdministrator();
        return JsonResult.OK(list);
    }


    @GetMapping("/delete/{id}")
    public JsonResult<Void> delete(@PathVariable("id") Integer id) {
        log.debug(id+"@@@@@@@@@@@@");
        administratorService.delete(id);
        return JsonResult.OK();
    }

    @PostMapping("/deletes")
    public JsonResult<Void> deletes(@RequestBody List<AdministratorVO> administratorVOList) {

        administratorService.deletes(administratorVOList);
        return JsonResult.OK();
    }

    @PostMapping("/update/password")
    public JsonResult<Void> password(@RequestBody AdministratorDTV administratorDTV) {
        log.debug(administratorDTV+"ok");
        administratorService.updateById(administratorDTV);
        return JsonResult.OK();
    }

    @GetMapping("/get/name")
    public JsonResult<List<String>> getName() {
        List<String> list = administratorService.getUserNameList();
        return JsonResult.OK(list);
    }

    @GetMapping("/get/role")
    public JsonResult<List<String>> getRole() {
        List<String> list = administratorService.getAdminTypeList();
        return JsonResult.OK(list);
    }

}
